<?php
class Pageley_Domain_Validator_Expression extends Pageley_Domain_Validator_Abstract {
	private $pattern;
	private $invalidMessage = "error.validation.invalid";

	public function __construct($pattern) {
		$this->pattern = $pattern;
	}
	
	public function setInvalidMessage($invalidMessage) {
		$this->invalidMessage = $invalidMessage;
	}

	public function validate($value, $propertyName, $object) {
		$errors = new Pageley_Util_ArrayMap();
        if($value !== null && $value !== "") {
    		$invalid = $this->rejectIfNotMatches($value, $this->pattern, $propertyName, $this->invalidMessage);
    		if($invalid) {
    			$errors->put($propertyName, $invalid);
    		}
        }
		return $errors;
	}
}